#ifndef _SQL_TABLES_H_
#define _SQL_TABLES_H_

#include <iostream>
#include <memory>
#include "glo_def.h"
#include "sqlconnection.h"

class SqlTables {
public:
	SqlTables(std::shared_ptr< MysqlConnection >sqlConn) : sqlConn_(sqlConn) {  }
	bool CreateUserInfo() {
		const char* pUserInfoTable = "\
									CREATE TABLE IF NOT EXISTS userinfo(\
									id        int(16)       NOT NULL primary key auto_increment,\
						            mobile    varchar(16)   NOT NULL default  '1100000000',\
                                    username  varchar(128)  NOT NULL default  '0',\
									verify    int(4)        NOT NULL default  '0' ,\
									registerm timestamp     NOT NULL default CURRENT_TIMESTAMP ,\
									money     int(4)        NOT NULL default '0' ,\
									INDEX     mobile_index(mobile)\
									)";
		if (!sqlConn_->Execute(pUserInfoTable)) {
			LOG_ERROR("Create sql table userinfo is failed . error:%s\n", sqlConn_->GetErrorInfo());
			return false;
		}
		return true;
	}

	// 创建单车表
	bool CreateBikeInfo() {
		const char* pBikeInfoTable = "\
									CREATE TABLE IF NOT EXISTS bikeinfo(\
									id          int          NOT NULL primary key auto_increment,\
								    devno       int          NOT NULL default 0 ,\
									status      tinyint(1)	 NOT NULL default 0 ,\
								    trouble	    int 		 NOT NULL default 0 , \
									tmsg        varchar(256) NOT NULL default '' , \
									latitude    double(10,6) NOT NULL default 0  comment '纬度' ,\
									longitude   double(10,6) NOT NULL default 0  comment '经度 ' , \
									unique(devno)\
									)";
		if (!sqlConn_->Execute(pBikeInfoTable)) {
			LOG_ERROR("Create sql table BikeInfoTable is failed . error:%s\n", sqlConn_->GetErrorInfo());
			return false;
		}
		return true;
	}
private:
	std::shared_ptr<MysqlConnection>sqlConn_;

};

#endif  // _SQL_TABLES_H_